%%%-------------------------------------------------------------------
%%% @author mirahs(2892727493@qq.com)
%%% @doc
%%%     进程相关
%%% @end
%%%-------------------------------------------------------------------
-module(util_proc).

-export([
    is_process_alive/1
    ,sleep/1
]).


%%%===================================================================
%%% API functions
%%%===================================================================

is_process_alive(Pid) when is_pid(Pid) ->
    PidNode = node(Pid),

    case node() =:= PidNode of
        true -> erlang:is_process_alive(Pid);
        false ->
            case rpc:call(PidNode, erlang, is_process_alive, [Pid]) of
                true -> true;
                false -> false;
                _ -> false
            end
    end;
is_process_alive(_) ->
    false.

%% 程序暂停执行时长(毫秒)
sleep(MicroTime) ->
    receive
    after MicroTime -> true
    end.
